package com.wu.server.service;

import com.wu.server.code.Code;
import com.wu.server.config.EncodeJson;
import com.wu.server.dao.GoodsRepository;
import com.wu.server.websocket.GoodsTopWebSocket;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.websocket.EncodeException;
import java.util.HashMap;

/**
 * @author Wugs
 * @version 1.0
 * @date 2021/3/4 22:12
 */
@Service
public class GoodsTopServer {
    @Autowired
    EncodeJson encodeJson;
    @Autowired
    GoodsRepository goodsRepository;
    @Autowired
    Code code;

    /**
     * 外部入口
     */
    @Async
    public void execute(){
        HashMap<String,Object> result = new HashMap<>();
        result.put("data", goodsRepository.getSalesOrder());
        HashMap<String,Object> meta = new HashMap<>();
        meta.put("code", code.GOODSTOP);
        meta.put("msg",code.getMsg(code.GOODSTOP));
        result.put("meta",meta);
        try {
            GoodsTopWebSocket.sendMessage(encodeJson.encode(result));
        } catch (EncodeException e) {
            e.printStackTrace();
        }
    }
}
